package com.lzgcoding.onlineshopapp.feature.detail.component

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import com.lzgcoding.onlineshopapp.R
import com.lzgcoding.onlineshopapp.ui.theme.Green
import com.lzgcoding.onlineshopapp.ui.theme.LargePadding
import com.lzgcoding.onlineshopapp.ui.theme.MediumPadding
import com.lzgcoding.onlineshopapp.util.formatCurrency

@Composable
fun BoxScope.DetailBottomBar(
    price: Double,
    oldPrice: Double
) {
    Row(
        modifier = Modifier
            .align(Alignment.BottomCenter)
            .fillMaxWidth()
            .padding(horizontal = LargePadding)
            .padding(bottom = MediumPadding)
            .navigationBarsPadding(),
        verticalAlignment = Alignment.CenterVertically,
        horizontalArrangement = Arrangement.spacedBy(LargePadding)
    ) {
        Surface(
            modifier = Modifier
                .weight(1f)
                .height(48.dp),
            shape = RoundedCornerShape(MediumPadding),
            border = BorderStroke(1.dp, Color(0xFFdcdcdc))
        ) {
            Text(
                text = buildAnnotatedString {
                    withStyle(
                        SpanStyle(
                            textDecoration = TextDecoration.LineThrough,
                            fontSize = MaterialTheme.typography.labelMedium.fontSize,
                        )
                    ) {
                        append(oldPrice.formatCurrency())
                    }
                    append(" ")
                    withStyle(
                        SpanStyle(
                            fontSize = MaterialTheme.typography.bodyMedium.fontSize,
                            color = Color.Red,
                            fontWeight = FontWeight.Bold
                        )
                    ) {
                        append(price.formatCurrency())
                    }
                },
                modifier = Modifier
                    .wrapContentSize()
                    .padding(horizontal = MediumPadding),
                textAlign = TextAlign.Center
            )
        }

        Button(
            onClick = {},
            modifier = Modifier
                .weight(1.5f)
                .height(48.dp),
            shape = RoundedCornerShape(MediumPadding),
            colors = ButtonDefaults.buttonColors(
                containerColor = Green,
                contentColor = Color.White
            )
        ) {
            Image(
                painter = painterResource(R.drawable.cart_icon),
                contentDescription = "cart-icon",
                colorFilter = ColorFilter.tint(Color.White)
            )
            Spacer(Modifier.width(LargePadding))
            Text(text = "Add to Cart")
        }
    }
}